#include <stdio.h>
#include <stdlib.h>
#include "../src/getMP4FrameCount.h"


int testForVideo(char * path, int except) {
	FILE *fileptr;  // File Pointer
	char *buffer;   // File Content Byte Array
	long filelen;	// File Length
	
	fileptr = fopen(path, "rb");          // Open the file in binary mode
	fseek(fileptr, 0, SEEK_END);          // Jump to the end of the file
	filelen = ftell(fileptr);             // Get the current byte offset in the file
	rewind(fileptr);                      // Jump back to the beginning of the file
	
	buffer = (char *)malloc(filelen * sizeof(char)); // Enough memory for the file
	fread(buffer, filelen, 1, fileptr);              // Read in the entire file
	fclose(fileptr);                                 // Close the file
	/*Get Frame Rate*/
	int frameCount = getFrameCount(buffer,filelen);
	if(frameCount == except){
		printf("\033[32m TEST PASS: %s \n\033[0m", path);
	}else {
		printf("\033[31m TEST FAIL: %s EXCEPT: %d BUT GET FRAME COUNT: %d\n\033[0m", path, except, frameCount);
	}
	return 0;
}


//测试方法
int main(){
	testForVideo("../resource/375.mp4", 375);
	testForVideo("../resource/125.mp4", 125);
}
